import { Controller, Get, Param, UseGuards } from '@nestjs/common'
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'
import { UsersService } from './users.service'

@UseGuards(JwtAuthGuard)
@Controller('api/users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get(':id')
  async findOne(@Param('id') id: string) {
    return await this.usersService.repo
      .createQueryBuilder('user')
      .where({ id })
      .select([
        'user.id',
        'profile.nickname',
        'profile.avatar',
        'profile.gender',
        'items'
      ])
      .leftJoin('user.profile', 'profile')
      .leftJoin('user.items', 'items')
      .getOneOrFail()
  }
}
